using KrasDD.Models;
using KrasDD.Services.Interfaces;

namespace KrasDD.Services.Implementations
{
    public class IdentityService : BaseService<IDENTITY>, IIdentityService
    {
        public IdentityService(IFreeSql freeSql, IServiceProvider serviceProvider) : base(freeSql, serviceProvider)
        {
        }

        public async Task<bool> CheckIsCurrentAsync(string id)
        {
            return await _freeSql.Select<IDENTITY>()
                .Where(x => x.ID == id)
                .FirstAsync(x => x.IS_CURRENT);
        }

        public async Task<List<ACCESS>> GetAccessesAsync(string identityId)
        {
            return await _freeSql.Select<ACCESS>()
                .Where(x => x.RELATED_ID == identityId)
                .ToListAsync();
        }
    }
}
